module MC.Call {
	export class MsgList {
		public constructor() {
		}

		private getlist() {
			MC.api('getmsglist', {}, (json: any) => {
				/// console.log(json); 
				$('.load').hide();
				this.upList(json);
			});
		}

		private upList(list: any) {
			for (let i = 0; i < list.length; i++) {
				let li = list[i];
				if (li.count == 0) {
					li.count = '';
				} else {
					li.count = `<span class="count">` + li.count + `</span>`;
				}
				let html = `<a href="jobWin.html?uid=` + li.other + `" 
					class="aui-six-list-item">
						<div class="aui-flex b-line">
							<div class="aui-flex-box">
								
								<h3>`+ li.count + ` ` + li.user.name + `</h3>
								
								<div class="clearfix">
								<p>`+ li.time + `</p>
									</div>
								</div>
							<div class="aui-flex-box" style="position:absolute;right:20px"
							><p>去交流</p>
						</div>
					</div>
				</a>`;
				$('#msglist').append(html);
			}
		}

	}


	export function getmsgUnreadCount() {
		if (!$('#toMessagePage')[0]) {
			return;
		}
		let count: any = localStorage.getItem('getmsgUnreadCount');
		if (count && count > 0) {
			let msgon = `<i class="msgOn"></i>`;
			$('#toMessagePage').append(msgon);
		}
		MC.api('getmsgUnreadCount', {}, (json: any) => {
			$('#business').text(json);
			localStorage.setItem('getmsgUnreadCount', json);
			if (json > 0) {
				if (!$('#toMessagePage .msgOn')[0]) {
					let msgon = `<i class="msgOn"></i>`;
					$('#toMessagePage').append(msgon);
				}
			} else {
				$('#toMessagePage .msgOn').hide();
			}
		});
	}
	$(() => {
		getmsgUnreadCount();
	});
}